home *** CD-ROM | disk | FTP | other *** search
- Path: news-relay.eworld.com!zdc!zippo!drn
- From: Clarence Chiang
- Newsgroups: comp.lang.c++
- Subject: Re: delete or delete [] ?
- Date: 1 Apr 1996 12:26:27 -0800
- Organization: Zippo
- Sender: http@doc.zippo.com
- Message-ID: <4jpe5j$3vo@doc.zippo.com>
- NNTP-Posting-Host: doorstop.spiderisland.com
-
- In article <4jp7n7$f8k@mcmail.CIS.McMaster.CA>, g9326161@mcmail.cis.McMaster.CA says...
- >
- >In almost all of C++ literatures, "delete aa" should be used iff aa is not an
- >array and "delete [] aa" should be used iff aa is an array. In following case,
- >what should I use?
- >
- >typedef int int10[10];
- >int* aa=new int10; // array of 10 integers.
- >
- >delete aa;
- >
- >or
- >
- >delete [] aa;
- >
- >For gcc (v2.6), it seems that both work. Which is the standard one?
- >
- >Thanks!
- >
- >Hong Shen
- >
-
- Actually it is quite simple, if the object is not an array, use delete; if it
- is an array use delete [].
-
- You example works, and so will any example, is because of the way deallocating
- a memory location occupy by an object and an array is just the same. The difference
- between delete and delete[] is that delete [] will call the destructor for each
- item in the array. Because int doesn't have a destructor, so it doesn't matter
- if you use delete or delete[].
-
- Clarence Chiang
- Spider Island Software
-
-